import 'package:flutter/material.dart';

class ScreenUtil {
  static late MediaQueryData _mediaQueryData;
  static late double screenWidth;
  static late double screenHeight;
  static late double defaultSize;
  static late Orientation orientation;

  // UI设计稿的尺寸
  static const double designWidth = 375;
  static const double designHeight = 812;

  static void init(BuildContext context) {
    _mediaQueryData = MediaQuery.of(context);
    screenWidth = _mediaQueryData.size.width;
    screenHeight = _mediaQueryData.size.height;
    orientation = _mediaQueryData.orientation;

    // 根据屏幕宽度计算基准尺寸
    defaultSize = screenWidth / designWidth;
  }

  // 根据设计稿尺寸计算实际尺寸
  static double setWidth(double width) {
    return width * defaultSize;
  }

  static double setHeight(double height) {
    return height * defaultSize;
  }

  // 根据设计稿尺寸计算实际字体大小
  static double setSp(double fontSize) {
    return fontSize * defaultSize;
  }

  // 获取屏幕宽度
  static double get getScreenWidth => screenWidth;

  // 获取屏幕高度
  static double get getScreenHeight => screenHeight;

  // 获取状态栏高度
  static double get getStatusBarHeight => _mediaQueryData.padding.top;

  // 获取底部安全区域高度
  static double get getBottomBarHeight => _mediaQueryData.padding.bottom;
}
